package com.tank.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/7/30 0030
 * Time: 下午 1:50
 * To change this template use File | Settings | File Templates.
 */
public class NodeTest4 {

    public static void main(String[] args) throws IOException {

        FileInputStream inputStream = new FileInputStream("input.txt");
        FileOutputStream outputStream = new FileOutputStream("out.txt");

        ByteBuffer byteBuffer = ByteBuffer.allocate(10);

        FileChannel inputChannel = inputStream.getChannel();
        FileChannel outChannel = outputStream.getChannel();

        while (true){
            int index = inputChannel.read(byteBuffer);
            System.out.println("index:"+index);
            if(index == -1){
                break;
            }

            byteBuffer.flip();
            outChannel.write(byteBuffer);

            byteBuffer.clear();
            byteBuffer.mark();
        }

        outputStream.close();
        inputStream.close();
    }
}
